/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.demo.scheduler.service.step.base;

import info.peigen.hotpot.demo.scheduler.domain.Task;
import lombok.extern.slf4j.Slf4j;

/**
 * <b>(AbstractStepProcessor)</b>
 *
 * @author Lihai
 * @version 1.0.0
 * @since 2023/9/9
 */
@Slf4j
public abstract class AbstractStepProcessor implements StepProcessor {

    public void handleCallback(TaskContext taskContext) {
        callback(taskContext);
        completed(taskContext);
        taskContext.getTask().getSendRequestNo().remove(taskContext.getCallBackResult().getMessage());
    }

    public abstract void callback(TaskContext taskContext);

    public abstract void execute(TaskContext context);

    public void completed(TaskContext taskContext) {

        Task          task        = taskContext.getTask();
        StepProcessor currentNode = task.getCurrentStep();
        //log.info("{}任务-第{}个节点完成", task.getName(), task.getTaskProcessor().steps().indexOf(currentNode) + 1);
        task.getTaskProcessor().executeNextStep(taskContext);
    }
}
